<template>
  <div class="app-container" style="padding: 0">
    <el-row class="row-mbinfo" style="margin-top: 5px;">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['customer:level:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5" style="margin-left: 10px">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['customer:level:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5" style="margin-left: 10px">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['customer:level:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <!--        <el-button-->
        <!--          type="warning"-->
        <!--          plain-->
        <!--          icon="el-icon-download"-->
        <!--          size="mini"-->
        <!--          @click="handleExport"-->
        <!--          v-hasPermi="['customer:level:export']"-->
        <!--        >导出-->
        <!--        </el-button>-->
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <div class="divTable">
      <el-table
        border
        v-loading="loading"
        :data="getPayLevelInfo"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column
          label="会员级别ID"
          align="center"
          v-if="show"
          prop="levelId"
        />
        <el-table-column label="客户等级" min-width="100" align="center" prop="customerGrade">
          <template slot-scope="scope">
          <span v-if="scope.row.customerPattern === '1'"
          >SVIP{{ scope.row.customerGrade }}</span
          >
          </template>
        </el-table-column>
        <el-table-column label="级别名称" min-width="100" align="center" prop="levelName" />
        <el-table-column label="定价" align="center" min-width="120">
          <template slot-scope="scope">
          <span>
            {{ scope.row.paymentRules.periodValidity + " ￥ " + scope.row.paymentRules.price/100 }}<br>
          </span>
          </template>
        </el-table-column>
        <el-table-column label="会员权益" min-width="150" align="center" prop="customerPrivlege" :show-overflow-tooltip="true">
          <template slot-scope="scope">
          <span
            v-for="(item, index) in scope.row.customerPrivileges || ''"
            :key="index"
          >
            {{ item.customerPrivlege }}
          </span>
          </template>
        </el-table-column>
        <el-table-column label="客户数" align="center" prop="customerNumber">
          <template slot-scope="scope">

            <span v-if="scope.row.customerNumber === null || scope.row.customerNumber === 0 ">0</span>
            <span v-if="scope.row.customerNumber != null && scope.row.customerNumber != 0 " style="color: #00AAFF;"
                  @click="customerLevelInfo(scope.row)">{{ scope.row.customerNumber }}</span>
          </template>
        </el-table-column>
        <el-table-column label="状态" min-width="100" align="center" prop="startStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.startStatus === '0'">已停止招募</span>
            <span v-if="scope.row.startStatus === '1'">会员招募中</span>
          </template>
        </el-table-column>
        <el-table-column label="卡面" align="center" prop="levelColor" width="120">
          <template slot-scope="scope">
            <div style="height: 40px;" align="center">
              <span v-if="scope.row.caedFace === '0'">
                <div :style="{
                  backgroundColor: scope.row.levelColor,
                  width: '100px',
                  height: '40px',
                  'border-radius': '4px',
                }"></div>
              </span>
              <span v-if="scope.row.caedFace === '1'">
                <div :style="{
                  backgroundImage: 'url(' + scope.row.levelImage + ')',
                  'background-repeat': 'no-repeat',
                  'background-size': '100% 100%',
                  width: '100px',
                  height: '40px',
                  'border-radius': '4px',
                }">
                  <!--                    <el-image :src="scope.row.levelImage" style="width: 100px;height: 30px"></el-image>-->
                </div>
              </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="直接分拥比例(%)" width="130" align="center" prop="directPointsPointsStr"/>
        <el-table-column label="间接分拥比例(%)" width="130" align="center" prop="indirectPointsPointsStr"/>
        <el-table-column label="自购分拥比例(%)" width="130" align="center" prop="selfbuyPointsPointsStr"/>
        <!--      <el-table-column label="直接分拥比例" align="center" prop="directPointsPoints"/>-->
        <!--      <el-table-column label="间接分拥比例" align="center" prop="indirectPointsPoints"/>-->
        <!--      <el-table-column label="自购分拥比例" align="center" prop="selfbuyPointsPoints"/>-->
        <!--      <el-table-column label="状态" align="center" prop="dataStatus" :formatter="dataStatusFormat"/>-->

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          min-width="140"
          fixed="right"
        >
          <template slot-scope="scope">
            <!--          <el-button-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-zoom-in"-->
            <!--            @click="handleShowDetail(scope.row)"-->
            <!--            v-hasPermi="['customer:level:query']"-->
            <!--          >查看-->
            <!--          </el-button>-->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-check"
              @click="startStatusUpdate(scope.row, (statu = 1))"
              v-if="scope.row.startStatus === '0'"
              v-hasPermi="['customer:level:edit']"
            >开始招募
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-close"
              @click="startStatusUpdate(scope.row, (statu = 0))"
              v-if="scope.row.startStatus === '1'"
              v-hasPermi="['customer:level:edit']"
            >停止招募
            </el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['customer:level:edit']"
            >修改
            </el-button>
            <!--          <el-button-->
            <!--            size="mini"-->
            <!--            type="text"-->
            <!--            icon="el-icon-delete"-->
            <!--            @click="handleDelete(scope.row)"-->
            <!--            v-hasPermi="['customer:level:remove']"-->
            <!--          >删除-->
            <!--          </el-button>-->
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <!-- 添加或修改客户等级对话框 -->


    <!-- 查看客户等级对话框 -->
    <el-dialog
      :title="viewTitle"
      :visible.sync="viewOpen"
      width="700px"
      append-to-body
    >
      <el-form ref="detailForm" label-width="100px">
        <el-row>
          <el-col
            :span="12"
            v-for="(item, index) in showData"
            :key="index"
            style="margin-top: -15px"
          >
            <el-form-item :label="`${item.label}：`">
              <span>{{ item.value }}</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="handCloseDetail"
        >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getLevelInfo,
  UpdateStartStatus,
  levelInfoDetail,
  delLevel,
  saveLevelPrivileageInfo,
  UpdateLevelPrivileageInfo,
  PrivileageInfo,
  getPayLevelInfo
} from "@/api/customer/level";
import { getUploadToken } from "@/api/monitor/file";
import { listPrivilege } from "@/api/customer/privilege";
import log from "../../monitor/job/log";
import Vue from "vue";
import selCoupon from "@/components/Activity/selCoupon";
import selGift from "@/components/Activity/selGift";
import ImageUpload from "@/components/ImageUpload/levelImage";

export default {
  name: "Level",
  components: {
    selGift,
    ImageUpload,
    selCoupon
  },
  data() {
    return {
      openR:false,
      openC:false,
      levelColor: '',
      resdata: [],
      isaddrule: false,
      price: "",
      periodValiditys: "",
      paymentRuless: [],
      paymentRules: [
        {
          periodValidity: "1个月",
        },
        {
          periodValidity: "3个月",
        },
        {
          periodValidity: "12个月",
        },
      ],
      coupon: false,
      Giftgiving: false,
      listPrivilegedatas: [],
      listPrivilegedata: [],
      hashs: [],
      hash:[],
      loadingmore: 1,
      loadingmore2: 1,
      //默认显示条数
      cou: 3,
      giftsNumber: "",
      productObj: {
        giftUid: "",
        giftName: "",
        productImg: "",
        stockNumber: "",
        receiveNumber: "",
      },
      infoList: [],
      infoList2: [],
      privilegeUid: "",
      property: [],
      giftUids: [],
      selUids: [],
      selList:  [],
      levelPrivileageGives: [],
      titleg: "",
      openg: false,
      isIndeterminate: false,
      inputone: "",
      listPrivilege: null,
      bgcolor: '#87CEEB',
      itemcolor: "",
      caedFace: "0",
      visible: false,
      previewImg: "",
      uploadImgUrl: "https://upload-z2.qiniup.com",
      upload_domain: "",
      uploadData: { token: "", key: "" },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户等级表格数据
      levelList: [],
      getPayLevelInfo: [],
      // 弹出层标题
      title: "",
      //查看详细标题
      viewTitle: "",
      // 是否显示弹出层
      open: false,
      //是否显示查看详细弹出层
      viewOpen: false,
      //查看详细数据
      showData: [],
      // 客户模式字典
      customerPatternOptions: [],
      // 状态字典
      dataStatusOptions: [],
      // 启动状态字典
      startStatusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        platformId: null,
        customerGrade: null,
        customerPattern: null,
        levelName: null,
        levelColor: null,
        levelIcon: null,
        minScore: null,
        fansNumber: null,
        performance: null,
        customerNumber: null,
        ruleId: null,
        dataStatus: null,
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null,
        gradeprivilegeId: null,
        startStatus: null,
        directPointsPoints: null,
        indirectPointsPoints: null,
        selfbuyPointsPoints: null,
      },
      columns: [
        {
          label: "会员级别ID",
          dataIndex: "levelId",
        },
        {
          label: "平台ID",
          dataIndex: "platformId",
        },
        {
          label: "客户等级",
          dataIndex: "customerGrade",
        },
        {
          label: "客户模式",
          dataIndex: "customerPattern",
        },
        {
          label: "级别名称",
          dataIndex: "levelName",
        },
        {
          label: "级别背景色",
          dataIndex: "levelColor",
        },
        {
          label: "级别图标",
          dataIndex: "levelIcon",
        },
        {
          label: "最小积分",
          dataIndex: "minScore",
        },
        {
          label: "粉丝数量",
          dataIndex: "fansNumber",
        },
        {
          label: "业绩",
          dataIndex: "performance",
        },
        {
          label: "客户数量",
          dataIndex: "customerNumber",
        },
        {
          label: "付费规则ID",
          dataIndex: "ruleId",
        },
        {
          label: "状态",
          dataIndex: "dataStatus",
        },
        {
          label: "创建时间",
          dataIndex: "createTime",
        },
        {
          label: "修改时间",
          dataIndex: "updateTime",
        },
        {
          label: "创建人",
          dataIndex: "createUser",
        },
        {
          label: "修改人",
          dataIndex: "updateUser",
        },
        {
          label: "客户权益ID",
          dataIndex: "gradeprivilegeId",
        },
        {
          label: "启动状态",
          dataIndex: "startStatus",
        },
        {
          label: "直接分拥比例",
          dataIndex: "directPointsPoints",
        },
        {
          label: "间接分拥比例",
          dataIndex: "indirectPointsPoints",
        },
        {
          label: "自购分拥比例",
          dataIndex: "selfbuyPointsPoints",
        },
      ],
      show: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        ShowName: [{ required: true, message: "请输入内容", trigger: "blur" }],
        levelName: [{ required: true, message: "请输入内容", trigger: "blur" }],
        minScore: [{ required: true, message: "请输入内容", trigger: "blur" }],
        fansNumber: [
          { required: true, message: "请输入内容", trigger: "blur" },
        ],
        performance: [
          { required: true, message: "请输入内容", trigger: "blur" },
        ],
      },
      checkExceptRisk: [],
    };
  },
  created() {
    this.getList();
    this.getDicts("customer_pattern").then((response) => {
      this.customerPatternOptions = response.data;
    });
    this.getDicts("sys_data_status").then((response) => {
      this.dataStatusOptions = response.data;
    });
    this.getDicts("customer_start_status").then((response) => {
      this.startStatusOptions = response.data;
    });
  },
  methods: {
    multipleSelection(data) {
      this.openR = false
      this.infoList = data;
      this.infoList.forEach(i=>{
        this.$set(i,'giftsNumber',1)
      })
    },
    multipleSelection2(data) {
      this.openC = false
      this.infoList2 = data;
      this.infoList2.forEach(i=>{
        this.$set(i,'couponNumber',1)
      })
    },
    toCloseBox() {
      this.openR = false;
    },
    toCloseBox2() {
      this.openC = false;
    },
    addrule(){
      if(this.paymentRuless.length){
        this.isaddrule = false;
        this.$message.error("付费等级设置一个价格");
      }else{
        this.isaddrule = true
      }
    },
    addPaymentRules(){
      this.paymentRuless.push({ periodValidity: this.periodValiditys,price:this.price });
      this.periodValiditys = ''
      this.price = ''
      this.isaddrule = false
      this.resdata = this.paymentRules
      for (let i = 0; i < this.paymentRules.length; i++) {
        for (let k = 0; k < this.paymentRuless.length; k++) {
          this.paymentRuless[k];
          if(this.paymentRules[i].periodValidity == this.paymentRuless[k].periodValidity) {
            this.paymentRules.splice(i,1)
          }
        }
      }
    },
    search() {
      this.privilege();
    },
    more() {
      let hashdata = this.hash.slice(3);
      for (let i = 0; i < hashdata.length; i++) {
        this.hashs.push(hashdata[i]);
      }
      this.loadingmore = 0;
    },
    more2() {
      let listPrivilege = this.listPrivilegedata.slice(3);
      for (let i = 0; i < listPrivilege.length; i++) {
        this.listPrivilegedatas.push(listPrivilege[i]);
      }
      this.loadingmore2 = 0;
    },

    handlepaymentr(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.paymentRules.push(this.paymentRuless[val]);
        this.paymentRuless.splice(val, 1);
      });

    },
    handleDeleteser(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.infoList.splice(val, 1);
      });
    },
    addcoupon(){
      this.$forceUpdate()
      this.openC = true;
      this.$nextTick(() => {
        this.$refs["selTable2"].greet2(this.infoList2);
      });
    },
    addgift() {
      this.$forceUpdate()
      this.openR = true;
      this.$nextTick(() => {
        this.$refs["selTable"].greet(this.infoList);
      });

    },
    handleDeleteser2(val, row) {
      // 模态框删除按钮
      this.$confirm("是否确认删除本条数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      }).then(() => {
        this.infoList2.splice(val, 1);
      });
    },
    giftDate(v,d) {
      //
      // v.map((v) => {
      //   let p = this.productObj;
      //   this.productObj.giftUid = v.giftUid;
      //   this.productObj.productImg = v.productImg;
      //   this.productObj.giftName = v.giftName;
      //   this.productObj.receiveNumber = v.receiveNumber;
      //   this.productObj.stockNumber = v.stockNumber;
      //
      //   this.infoList.push(this.productObj);
      // });
      this.selUids = [];
      this.selList= [];
      this.selList= v;
      this.infoList =v;
      this.selUids.push(d);
      this.openg = false;
    },
    editLevelDia() {
      this.reset();
      this.paymentRuless = [];
    },
    unit(platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true;
        }
      }
    },
    unit2(platformUnit) {
      for (let i = 0; i < this.checkExceptRisk.length; i++) {
        if (this.checkExceptRisk[i].platformUnit == platformUnit) {
          return true;
        }
      }
    },
    privilege(val, item, index, hashs) {
      if (item!=null){
        if (val == true) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = "赠品";
            this.coupon = true;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = "赠品";
            this.Giftgiving = true;
          }
          this.checkExceptRisk.push(item);
        }
        if (val == false) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = null;
            this.coupon = false;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = null;
            this.Giftgiving = false;
          }

          for (let i = 0; i < this.checkExceptRisk.length; i++) {
            if (item == this.checkExceptRisk[i]) {
              this.checkExceptRisk.splice(i, 1);
            }
          }
        }
        item.privilegeStatus = val;
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName){
            this.checkExceptRisk[i] = item;
          }
        }
      }
    },
    privilege2(val, item, index, listPrivilegedatas) {
      if (item!=null){
        if (val == true) {
          if (item.privleageName == "coupon") {
            item.privilegeValue = "赠品";
            this.coupon = true;
          }
          if (item.privleageName == "gift") {
            item.privilegeValue = "赠品";
            this.Giftgiving = true;
          }
          this.checkExceptRisk.push(item);
        }
        if (val == false) {
          if (item.privleageName == "coupon") {
            item.privilegeStatus = false;
            item.privilegeValue = null;
            this.coupon = false;
          }
          if (item.privleageName == "gift") {
            item.privilegeStatus = false;
            item.privilegeValue = null;
            this.Giftgiving = false;
          }

          for (let i = 0; i < this.checkExceptRisk.length; i++) {
            if (item == this.checkExceptRisk[i]) {
              if (this.checkExceptRisk[i].platformUnit == this.unitss) {
                this.unitss = null;
              }
              this.checkExceptRisk.splice(i, 1);
            }
          }

        }
        item.privilegeStatus = val;
        for (let i = 0; i < this.checkExceptRisk.length; i++) {
          if (this.checkExceptRisk[i].privleageName === item.privleageName){
            this.checkExceptRisk[i] = item;
          }
        }
      }
    },
    /** 查询客户等级列表 */
    getList() {
      this.loading = true;
      getPayLevelInfo(this.queryParams).then((response) => {
        this.getPayLevelInfo = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 客户模式字典翻译
    customerPatternFormat(row, column) {
      return this.selectDictLabel(
        this.customerPatternOptions,
        row.customerPattern
      );
    },
    // 状态字典翻译
    dataStatusFormat(row, column) {
      return this.selectDictLabel(this.dataStatusOptions, row.dataStatus);
    },
    // 启动状态字典翻译
    startStatusFormat(row, column) {
      return this.selectDictLabel(this.startStatusOptions, row.startStatus);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        levelId: null,
        platformId: null,
        customerGrade: null,
        customerPattern: null,
        levelName: null,
        levelColor: null,
        levelIcon: null,
        minScore: null,
        fansNumber: null,
        performance: null,
        customerNumber: null,
        ruleId: null,
        dataStatus: "0",
        createTime: null,
        updateTime: null,
        createUser: null,
        updateUser: null,
        gradeprivilegeId: null,
        startStatus: "0",
        directPointsPoints: null,
        indirectPointsPoints: null,
        selfbuyPointsPoints: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.levelId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    getlistPrivilege() {
      PrivileageInfo().then((res) => {
        this.form = res;
        this.listPrivilegedata = [];
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
            this.hash.push(this.form.customerLevelPrivleageVos[i]);
          }
        }
        for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
          if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
            this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i]);
          }
        }
        if (this.loadingmore == 1) {
          if (this.hash.length >= 3) {
            this.hashs = this.hash.slice(0, this.cou);
          }
        }

        if (this.loadingmore2 == 1) {
          if (this.listPrivilegedata.length >= 3) {
            this.listPrivilegedatas = this.listPrivilegedata.slice(0, this.cou);
          }
        }
      });
    },
    /** 新增按钮操作 */
    handleAdd() {

      // this.reset();
      // this.hashs = [];
      // this.listPrivilegedatas = []
      // this.infoList = []
      // this.infoList2 = []
      this.$router.push("/payPatternUpdate/payPatternUpdate");
      // this.open = true;
      // this.title = "添加客户等级";
    },
    /** 查看详情按钮操作 **/
    handleShowDetail(row) {
      this.viewOpen = true;
      this.viewTitle = "查看客户等级";
      this.showData = [];
      this.columns.forEach((item) => {
        this.showData.push({
          label: item.label,
          value: row[item.dataIndex],
        });
      });
    },
    handCloseDetail() {
      this.viewOpen = false;
      this.showData = [];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$router.push("/payPatternUpdate/payPatternUpdate/" + row.levelId);
      // this.reset();
      // const levelId = row.levelId || this.ids;
      // levelInfoDetail(levelId).then((response) => {
      //   this.form = response.customerLevel;
      //   this.bgcolor = this.form.levelColor;
      //   this.open = true;
      //   this.title = "修改客户等级";
      //   this.hash = [];
      //   this.listPrivilegedata = [];
      //   let giveobjs = new Array();
      //   let giveobjs2 = new Array();
      //   for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
      //     if (
      //       this.form.customerLevelPrivleageVos[i].levelPrivileageGives != null
      //     ) {
      //       let giveList =
      //         this.form.customerLevelPrivleageVos[i].levelPrivileageGives;
      //       giveList.forEach((item) => {
      //         if (item.giveType == "coupon"){
      //           let giveobj2 = new Object();
      //           giveobj2.couponTypeName = item.giveName;
      //           giveobj2.couponUid = item.giveGiftId;
      //           giveobj2.couponNumber = item.giveNumber;
      //           giveobj2.stock = item.giveSumNumber;
      //           giveobjs2.push(giveobj2);
      //         }
      //         if (item.giveType == "gift"){
      //           let giveobj = new Object();
      //           giveobj.giftName = item.giveName;
      //           giveobj.giftUid = item.giveGiftId;
      //           giveobj.giftsNumber = item.giveNumber;
      //           giveobj.stockNumber = item.giveSumNumber;
      //           giveobjs.push(giveobj);
      //         }
      //       });
      //       this.infoList2 = giveobjs2;
      //       this.infoList = giveobjs;
      //     }
      //   }

      //   this.paymentRuless.push(this.form.paymentRules);
      //   for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
      //     this.checkExceptRisk.push(this.form.customerLevelPrivleageVos[i]);
      //     if (this.checkExceptRisk[i].privilegeStatus == true) {
      //       if (this.checkExceptRisk[i].privleageName == "coupon") {
      //         this.coupon = true;
      //       }
      //       if (this.checkExceptRisk[i].privleageName == "gift") {
      //         this.Giftgiving = true;
      //       }
      //     }
      //   }
      //   for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
      //     if (this.form.customerLevelPrivleageVos[i].isUpgrade == 0) {
      //       this.hash.push(this.form.customerLevelPrivleageVos[i]);
      //     }
      //   }
      //   for (let i = 0; i < this.form.customerLevelPrivleageVos.length; i++) {
      //     if (this.form.customerLevelPrivleageVos[i].isUpgrade == 1) {
      //       this.listPrivilegedata.push(this.form.customerLevelPrivleageVos[i]);
      //     }
      //   }

      //   if (this.loadingmore == 1) {
      //     if (this.hash.length >= 3) {
      //       this.hashs = this.hash.slice(0, this.cou);
      //     }
      //   } else if (this.loadingmore == 0) {
      //     this.hashs = this.hash;
      //   }
      //   if (this.loadingmore2 == 1) {
      //     if (this.listPrivilegedata.length >= 3) {
      //       this.listPrivilegedatas = this.listPrivilegedata.slice(0, this.cou);
      //     }
      //   } else if (this.loadingmore2 == 0) {
      //     this.listPrivilegedatas = this.listPrivilegedata;
      //   }
      // });
    },
    startStatusUpdate(row, statu) {
      let levelName = row.levelName;
      let text;
      let hiht;
      if (statu === 0) {
        text = "停用";
        hiht = "是否停用名称为"+levelName+"的等级?停用后将不可购买该等级";
      }
      if (statu === 1) {
        text = "启动";
        hiht = "是否启动名称为"+levelName+"的等级?启动后将开始销售该等级";
      }
      if(row.customerPattern == "0"){
        row.customerPattern = "1";
      }else{
        row.customerPattern = "0";
      }
      let startStatus = row.startStatus;
      if(row.startStatus == "0"){
        row.startStatus = "1";
      }else{
        row.startStatus = "0";
      }
      row.customerPattern = "1";
      this.$confirm(hiht, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let than = this;
        UpdateStartStatus(row).then((response) => {
          this.getList();
          this.msgSuccess(text + "成功");
        });
      }).catch(() => {
        row.startStatus = startStatus;
      });
      // this.$confirm(
      //   '是否"' + text + '"名称为"' + levelName + "的等级?",
      //   "警告",
      //   {
      //     confirmButtonText: "确定",
      //     cancelButtonText: "取消",
      //     type: "warning",
      //   }
      // )
      //   .then(function () {
      //
      //   }).catch(() => {
      //
      // })
    },
    getNumber(k,i,idx){
      i=parseInt(i)
      k=parseInt(k)
      if(i>k){
        this.infoList[idx].giftsNumber=1
        this.msgError("赠品数不能大于赠品总数");
      }
    },
    getCouponNumber(k,i,idx){
      i=parseInt(i)
      k=parseInt(k)
      if(i > k){
        this.infoList2[idx].couponNumber=1
        this.msgError( "赠送数不能大于优惠券总数");
      }
    },
    //跳转自定义权益
    skipPrivileage() {
      this.$router.push("/privilege/data/");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          let CustomerLevelVo = this.form;
          CustomerLevelVo.customerPattern = 1;
          let caedFace = this.form.caedFace;
          if(caedFace == undefined){
            caedFace = '0';
          }
          CustomerLevelVo.caedFace = caedFace;
          if (
            CustomerLevelVo.levelColor == null &&
            CustomerLevelVo.levelColor == "" &&
            CustomerLevelVo.levelImage == null &&
            CustomerLevelVo.levelImage == ""
          ) {
            CustomerLevelVo.levelColor = "#87CEEB";
          }
          if (CustomerLevelVo.caedFace == 0) {
            CustomerLevelVo.levelColor = this.bgcolor;
          } else {
            CustomerLevelVo.levelImage = this.form.levelImage;
          }
          Vue.set(CustomerLevelVo, "paymentRules", this.paymentRuless[0]);
          Vue.set(CustomerLevelVo, "customerPrivileges", this.checkExceptRisk);
          let giveobjs = new Array();
          let giveobjs2 = new Array();
          CustomerLevelVo.customerPrivileges.forEach((item) => {
            if(item.privleageName == "gift") {
              if (item.isGive == "1" && item.privilegeStatus == true) {
                let privleageName = item.privleageName;
                this.infoList.forEach((infoItem) => {
                  let giveobj = new Object();
                  giveobj.giveName = infoItem.giftName;
                  giveobj.giveGiftId = infoItem.giftUid;
                  giveobj.giveNumber = infoItem.giftsNumber;
                  giveobj.giveSumNumber = infoItem.stockNumber;
                  giveobj.giveType = privleageName;
                  giveobjs.push(giveobj);
                });
                Vue.set(item, "levelPrivileageGives", giveobjs);
              }
            }
          });
          CustomerLevelVo.customerPrivileges.forEach((item) => {
            if(item.privleageName == "coupon") {
              console.log(item,'1302');
              if (item.isGive == "1" && item.privilegeStatus == true) {
                let privleageName = item.privleageName;
                this.infoList2.forEach((i) => {
                  let giveobj2 = new Object();
                  giveobj2.giveName = i.couponTypeName;
                  giveobj2.giveGiftId = i.couponUid;
                  giveobj2.giveNumber = i.couponNumber;
                  giveobj2.giveSumNumber = i.stock;
                  giveobj2.giveType = privleageName;
                  giveobjs2.push(giveobj2);
                  console.log(giveobjs2,'1313');
                });
                Vue.set(item, "levelPrivileageGives", giveobjs2);
              }
            }
          });
          if (this.form.levelId != null) {
            console.log(CustomerLevelVo,'修改数据');
            UpdateLevelPrivileageInfo(CustomerLevelVo).then((response) => {
              this.msgSuccess("修改成功");
              CustomerLevelVo = null
              this.open = false;
              this.getList();
            });
          } else {
            console.log(CustomerLevelVo,'添加数据');
            saveLevelPrivileageInfo(CustomerLevelVo).then((response) => {
              this.msgSuccess("新增成功");
              CustomerLevelVo = null
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 取消按钮
    Formcancel() {
      this.colseLevel();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const levelIds = row.levelId || this.ids;
      this.$confirm(
        '是否确认删除客户等级?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delLevel(levelIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "customer/level/export",
        {
          ...this.queryParams,
        },
        `customer_level.xlsx`
      );
    },
    // 上传图片之前
    beforeUpload(file) {
      let _self = this;
      return new Promise((resolve, reject) => {
        getUploadToken()
          .then((response) => {
            _self.uploadData.key = response.data.key;
            _self.uploadData.token = response.data.token;
            _self.upload_domain = response.data.domain;
            resolve(true);
          })
          .catch((err) => {
            reject(false);
          });
      });
    },
    beforeRemove(file, fileList) {
      return new Promise((resolve, reject) => {
        this.$confirm(`是否删除该图片？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.previewImg = "";
            this.$message({ type: "success", message: "删除成功!" });
            resolve();
            return true;
          })
          .catch((err) => {
            reject(err);
            return false;
          });
      });
    },
    handleRemove(file, fileList) {
      this.previewImg = "";
    },
    handleSuccess(response, file, fileList) {
      this.previewImg = this.upload_domain + response.key;
    },
  },
};
</script>
<style lang="less" scoped>
.el-input {
  width: 200px;
}
/deep/ .el-upload--picture-card {
  width: 60px;
  height: 60px;
}
/deep/ .el-upload {
  width: 60px;
  height: 60px;
  line-height: 60px;
  margin-top: 10px;
}
/deep/ .el-upload-list--picture-card .el-upload-list__item {
  width: 60px;
  height: 60px;
  line-height: 60px;
}
/deep/ .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 60px;
  height: 60px;
  line-height: 60px;
}
/deep/ .avatar {
  width: 60px;
  height: 60px;
}
.el-icon-plus {
  font-size: 14px;
}
.bgcard {
  width: 340px;
  height: 180px;
  border-radius: 15px;
  position: absolute;
  top: 30px;
  right: 25px;
}
.font-a {
  font-size: 22px;
  font-weight: 900;
  color: #ffffff;
  margin: 20px 0 0 20px;
}
.font-b {
  font-size: 12px;
  color: #ffffff;
  margin: 0px 0 0 20px;
}
.font-b span {
  font-size: 24px;
  font-weight: 700;
}
.font-c {
  width: 89%;
  border: 1px solid #fff;
  margin: 20px 0 0 20px;
}
.itemyanse {
  width: 100%;
  height: 100%;
  display: flex;
  flex: 1;
  margin-top: 5px;
}
.bgyanse {
  width: 20%;
  margin-right: 5px;
}
// .elradio {
//   margin-top: 12px;
// }
.formitem {
  width: 100%;
  height: 100%;
  position: relative;
  top: -30px;
}
.formitem-p {
  font-size: 20px;
}
.qy {
  font-size: 20px;
}
.Unitdiv {
  display: inline-block;
  width: 30px;
  height: 29px;
  border-left: 1px solid #dcdee0;
  border-right: 1px solid #dcdee0;
  position: relative;
  top: 0;
  right: 31px;
  background-color: #f7f8fa;
  text-align: center;
  line-height: 29px;
}
.el-input {
  width: 120px;
}
.selectgift {
  margin-top: 10px;
}
.el-checkbox {
  margin-bottom: 10px;
}
.GiftBag {
  position: relative;
}
.inputcolumn {
  // position: absolute;
  // top: 10px;
  // right: 25px;
  // margin-left: 80%;
  .el-input {
    width: 60px;
  }
}
.el-checkbox {
  width: 70px;
}
.couponGift {
  width: 100px;
  height: 30px;
  font-size: 14px;
  color: rgb(0, 175, 255);
}
</style>
